var requestUrl,requestUrlMis, userKey,env = window.windowEnvir;
if(env === 'firefly'){
    requestUrl = "/api";
    requestCaseUrl = "/capi";
    requestUrlMis = "/mis";
    userKey = "F311E3F5D0E5B54D";
    requestLawyerService = "https://gw.winhc.cn/winhc-lawyer-service";
    winhc_api_vip_url = 'https://gw.winhc.cn/win-coin'; //生产
    websiteUrl = "https://www.winhc.cn";
}else{
    requestUrl = "/api";
    requestCaseUrl = "/capi";
    requestUrlMis = "/mis";
    userKey = "0123456789012345";
    requestLawyerService = "https://twww.winhc.net/api/winhc-lawyer-service";
    winhc_api_vip_url = 'https://twww.winhc.net/api/win-coin'; //生产
    websiteUrl = "https://twww.winhc.net";
}
//初始值
var appid = "WEB_SITE",
    apiVersion = "1.0",
    sessionId = "",
    osType = "",
    deviceId = "",
    brand = "",
    osVersion = "",
    appVersion = "";
var firefly_IM_request = {
    getRequest:function(requestType,serviceName,bodyInfo,successFn,errorFn,type){
        //如果serviceName为“/im/login”登录，则需要加密密码
        var bizInfo = bodyInfo;
        var data = {}
        let requrl = requestUrl;
        if(serviceName == '/firefly-login/login/open/login'){
            bizInfo.password = MD5((bizInfo.password).toUpperCase() + userKey); 
        }
        data = bizInfo;
        if(requestType === "put" || requestType === 'delete' || requestType === 'post'){
            data = JSON.stringify(data);
        }
        if(type === "lawyerConsult"){
            requrl = requestLawyerService;
        }else if(type === 'wincoin'){
            requrl = winhc_api_vip_url;
        }
        // console.log("data数据=",bizInfo)
        $.ajax({
            url:requrl + serviceName,
            method:requestType,
            // cache:false,
            headers: {
                'Accept': "application/json; charset=utf-8",
                'appid': "WEB_SITE",
                'apiVersion': "1.0",
                'sessionId': sessionStorage.getItem("sessionId"),
                'osType': "",
                'deviceId': "",
                'brand': "",
                'osVersion': "",
                'appVersion': ""
            },
            data:data,
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            success:function(data,textStatus,jqXHR){
                // console.log("成功返回=",data)
                successFn(data);
            },
            error:function(xhr,textStatus){
                topTipGlobalMsg(xhr.statusText,2000)
                // console.log('失败返回=',xhr)
                if(xhr.status == '401'){
                    sessionStorage.setItem('uid', "");
                    sessionStorage.setItem('sdktoken', "");
                    sessionStorage.setItem('userId',"");
                    sessionStorage.setItem('sessionId',"");
                    sessionStorage.setItem('iMmobileNo',"");
                    // window.location.href = './login.html';
                    window.location.href = websiteUrl + "?login=false";
                }
                

                errorFn(xhr);
            }
        })
    },
}